package com.spcloud.demo.zuul.config;

import com.spcloud.demo.zuul.filter.AccessFilter;
import com.spcloud.demo.zuul.route.CustomSimpleRouteLocator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayConfiguration {

    @Autowired
    private ZuulProperties zuulProperties;

    @Bean
    public AccessFilter accessFilter() {
        return new AccessFilter();
    }
//    @Bean
    public CustomSimpleRouteLocator routeLocator() {
        CustomSimpleRouteLocator customSimpleRouteLocator = new CustomSimpleRouteLocator("/", zuulProperties);
        return customSimpleRouteLocator;
    }

    @Bean
    public PatternServiceRouteMapper serviceRouteMapper() {
        return new PatternServiceRouteMapper(
                "(?<name>^.+)-(?<version>v.+$)",
                "${version}/${name}");
    }
}
